package com.huanbao.nongwu.controller.base;

import com.huanbao.common.pojo.nwrabc.SysUser;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/* ━━━━━━佛祖保佑━━━━━━
 *                  ,;,,;
 *                ,;;'(    社
 *      __      ,;;' ' \   会
 *   /'  '\'~~'~' \ /'\.)  主
 * ,;(      )    /  |.     义
 *,;' \    /-.,,(   ) \    码
 *     ) /       ) / )|    农
 *     ||        ||  \)
 *     (_\       (_\
 * ━━━━━━永无BUG━━━━━━
 * @author ：zjq
 * @date ：2020/8/14 15:39
 * @description: TODO
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 */
public class BaseWebController {

    public HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public HttpServletResponse getResponse() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
    }


    /**
     * 获取 用户信息
     * {@link com.huanbao.gateway.fliter.AuthorizationFilter#wrapHeader()}
     *
     * @return
     */
    public SysUser getUserInfo() {

        HttpServletRequest request = getRequest();
        String userId = request.getHeader("userId");
        String userName = request.getHeader("userName");
        String loginName = request.getHeader("loginName");
        String useremail = request.getHeader("useremail");
        String department = request.getHeader("department");
        String telephone = request.getHeader("telephone");


        SysUser u = new SysUser();
        u.setId(Integer.parseInt(userId));
        u.setUsername(userName);
        u.setLoginname(loginName);
        u.setUseremail(useremail);
        u.setDepartment(department);
        u.setTelephone(telephone);
        return u;

    }


}
